package com.zqwh.storemonitor.activity;

import android.os.Handler;
import android.view.View;

public abstract class MyClickListener implements View.OnClickListener {
    private static final int TIMEOUT = 400;

    private int clickCount = 0;
    private Handler handler;

    protected MyClickListener() {
        handler = new Handler();
    }

    @Override
    public void onClick(final View v) {
        clickCount++;
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                if (clickCount == 1) {
                    onSingleClick(v);
                } else if (clickCount == 2) {
                    onDoubleClick(v);
                }
                handler.removeCallbacksAndMessages(null);
                clickCount = 0;
            }
        }, TIMEOUT);
    }

    /**
     * 单击实现
     *
     * @param v 视图
     */
    public abstract void onSingleClick(View v);

    /**
     * 双击实现
     *
     * @param v 视图
     */
    public abstract void onDoubleClick(View v);
}
